define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'manageuser.user/index',
        add_url: 'manageuser.user/add',
        edit_url: 'manageuser.user/edit',
        delete_url: 'manageuser.user/delete',
        export_url: 'manageuser.user/export',
        modify_url: 'manageuser.user/modify',
        adopt_url: 'manageuser.user/adopt_url',
    };
    var Controller = {
        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                cols: [[
                    {field: 'id', title: 'ID', search: false},
                    {field: 'nickname', title: '用户昵称'},
                    {field: 'referrer_user', title: '推荐人', search: false},
                    {field: 'avatar', minWidth: 80, title: '头像', search: false, templet: ea.table.image},
                    {field: 'create_time', title: '注册时间', search: false},
                    {field: 'gender', title: '性别',selectList: {0:'未知',1: '男',2: '女'}},
                    {field: 'is_check', title: '是否是分销商',selectList: {1: '是',2: '否'}},
                    {field: 'status', title: '用户状态', templet: ea.table.switch, search: false},
                    // {title: '操作', templet: ea.table.tool,operat:[
                    //     [
                    //         {
                    //             text: '发放优惠券',
                    //             url: init.edit_url,
                    //             method: 'open',
                    //             auth: 'edit',
                    //             class: 'layui-btn layui-btn-xs layui-btn-success'
                    //         }
                    //    ],
                    //    [
                    //         {
                    //             text: '成为分销商',
                    //             title: '确定成为分销商吗？',
                    //             url: init.adopt_url,
                    //             method: 'request',
                    //             auth: 'edit',
                    //             class: 'layui-btn layui-btn-xs layui-btn-normal'
                    //         }
                    //     ]
                    // ]},
                    {title: '操作', templet: function (d) {
                            if(d.is_check == 1){
                                return '<button class="layui-btn layui-btn-xs layui-btn-success" data-open="manageuser.user/edit?id='+d.id+'"  data-title="发放优惠券" >发放优惠券</button>' +
                                    '<button class="layui-btn layui-btn-normal layui-btn-sm layui-btn-disabled" >成为分销商</button>';
                            }else{
                                return '<button class="layui-btn layui-btn-xs layui-btn-success" data-open="manageuser.user/edit?id='+d.id+'"  data-title="发放优惠券" >发放优惠券</button>' +
                                    '<button class="layui-btn layui-btn-xs layui-btn-normal" data-request="manageuser.user/adopt_url?id='+d.id+'"  data-title="确定成为分销商吗？" >成为分销商</button>'
                            }
                        }
                    },
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});